//
//  InformationViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/8/20.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import XLPagerTabStrip

class InformationViewController: KMPageViewController {

    override func viewDidLoad() {
        topBarStyle()
        super.viewDidLoad()
        
        self.title = information_title
        
        self.buttonBarView.snp.remakeConstraints { (make) in
            make.left.top.equalToSuperview()
            make.right.equalToSuperview().offset(RATIO_H(maxNum: -40))
            make.height.equalTo(RATIO_H(maxNum: 40))
        }
        
        let button = UIButton()
        button.layer.contents = #imageLiteral(resourceName: "bottom_arrow").cgImage
        button.addTarget(self, action: #selector(moreLabel), for: .touchUpInside)
        self.view.addSubview(button)
        
        button.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.right.equalToSuperview().offset(RATIO_H(maxNum: -10))
            make.width.height.equalTo(RATIO_H(maxNum: 20))
        }
    }
    
    //AMRK: 顶部滚动条样式
    fileprivate func topBarStyle() {
        
        settings.style.buttonBarBackgroundColor = UIColor.clear
        settings.style.buttonBarItemTitleColor = UIColor.black
        settings.style.buttonBarItemBackgroundColor = UIColor.clear
        settings.style.selectedBarBackgroundColor = UIColor.red
        settings.style.buttonBarItemFont = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        settings.style.selectedBarHeight = 3
        settings.style.buttonBarHeight = RATIO_H(maxNum: 40)
        
        //修改选中字体颜色
        changeCurrentIndexProgressive = {(oldCell,newCell,progressPercentage,changeCurrentIndex,animated) in
            
            oldCell?.label.textColor = UIColor.black
            newCell?.label.textColor = UIColor.red
        }
    }
    
    //MARK: 更多标签
    @objc fileprivate func moreLabel() {
    
        let moreLabelVC = MoreLabelViewController()
        moreLabelVC.labelBlock = {(index) in
           self.moveToViewController(at: index.row, animated: true) //切换至选择标签
        }
        self.present(moreLabelVC, animated: false, completion: nil)
    }
    

    //MARK: 滑动的子控制
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        
        let titleArray = [todayHeadlines,featuredFavourites,latestNews,littleWhiteRaiders,useCardRaiders,quotaStrategy,creditCardEvaluation,popularWool,exclusiveRecommendation,specialReport,newCardExpress,bankInformation]
        let urlArray = ["9","0","1","10","11","12","13","14","16","17","18","19"]
        
        var viewControllers = [UIViewController]()
        
        for i in 0..<titleArray.count {
            let newsVC = NewsViewController.init(urlString: urlArray[i])
            newsVC.itemInfo.title = titleArray[i]
            viewControllers.append(newsVC)
        }
        
        return viewControllers
    }
    
}
